var path = require('path');
var webpackDevServer = require('webpack-dev-server');
var webpack = require('webpack');

var work_path = process.cwd();

var config = require(path.join(work_path, 'webpack.config.js'));

var port = 3000;

config.devtool = 'cheap-module-inline-source-map';

Object.keys(config.entry).forEach(function (name) {
    config.entry[name] = [`webpack-dev-server/client?http://127.0.0.1:${port}`,'webpack/hot/only-dev-server'].concat(config.entry[name])
})

config.plugins.push(
    new webpack.HotModuleReplacementPlugin()
)

var server = new webpackDevServer(webpack(config), {
    hot: true,
    contentBase: 'dist',
    disableHostCheck: true
})

server.listen(port, ()=> {
    console.log(`dev server listening on port ${port}`);
});